/*
 * lib2Desa - Another 2D game library in C++
 * Copyright (C) 2009 Erivaldo Xavier de Lima Filho
 *
 * This program is free software and is distributed under GNU General Public License version 3. You can modify and/or redistribute
 * it under the terms of GPL version 3 or posterior version. This program comes with NO WARRANTY, for more details, see LICENSE,
 * or <http://www.gnu.org/licenses>.
 *
 * Contact info:
 *
 *	Erivaldo Xavier de Lima Filho, desadoc@gmail.com
 *
 */

#include "Lua/GraphicDevice.hpp"

#include "Core/IGraphicDevice.hpp"
#include "SDL/GraphicDevice.hpp"
using namespace lib2Desa;

#include <string.h>

#include <iostream>
using namespace std;

int GraphicDevice_new(lua_State* L)
{
	const char* devname = lua_tostring(L, 1);
	IGraphicDevice* _new;

	if(strcmp(devname, "SDL") == 0)
	{
		_new = new SDL::GraphicDevice();
	}
	else return 0;

	size_t nbytes = sizeof(_new);
	IGraphicDevice **ud = (IGraphicDevice**) lua_newuserdata(L, nbytes);
	(*ud) = _new;

    luaL_getmetatable(L, "lib2Desa.GraphicDevice");

	lua_pushstring(L, "__index");
	lua_pushvalue(L, -2);
	lua_settable(L, -3);

	lua_setmetatable(L, -2);

	return 1;
}

int GraphicDevice_initScreen(lua_State* L)
{
	IGraphicDevice** ud = (IGraphicDevice**) lua_touserdata(L,1);

	int width = (int) lua_tonumber(L,2);
	int height = (int) lua_tonumber(L,3);

	(*ud)->initScreen(width, height);

	return 0;
}
